import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: HomeView,
      children:[
        {
          path: '/userList',
          name: 'userList',
          component: () => import('../views/User/UserList.vue'),
        },
        {
          path: '/userAdd',
          name: 'userAdd',
          component: () => import('../views/User/UserAdd.vue'),
        },
        {
          path: '/goodsAdd',
          name: 'goodsAdd',
          component: () => import('../views/Goods/GoodsAdd.vue'),
        },
        {
          path: '/goodsUpdate',
          name: 'goodsUpdate',
          component: () => import('../views/Goods/GoodsUpdate.vue'),
        },

        {
          path: '/goodsList',
          name: 'goodsList',
          component: () => import('../views/Goods/GoodsList.vue'),
        },

        {
          path: '/rBACList',
          name: 'rBACList',
          component: () => import('../views/RBAC/RBACList.vue'),
        },

        {
          path: '/rABCAdd',
          name: 'rABCAdd',
          component: () => import('../views/RBAC/RABCAdd.vue'),
        },

        {
          path: '/RBACFantian',
          name: 'RBACFantian',
          component: () => import('../views/RBAC/RBACFantian.vue'),
        },
        {
          path: '/orderinfoList',
          name: 'orderinfoList',
          component: () => import('../views/Order/OrderinfoList.vue'),
        },

        {
          path: '/orderinfocarousel',
          name: 'orderinfocarousel',
          component: () => import('../views/Order/Orderinfocarousel.vue'),
        },

        {
          path: '/goodchart',
          name: 'goodchart',
          component: () => import('../views/Goods/Goodchart.vue'),
        },

      ]
    },

    
    {
      path: '/about',
      name: 'about',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/AboutView.vue'),
    },

    {
      path: '/userinfoLogn',
      name: 'userinfoLogn',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/Long/UserinfoLogn.vue'),
    },

  ],
})


export default router



//路由守卫
router.beforeEach((to,from,next)=>{
  console.log("to=",to.path,"from=",from.path);
  if(to.path=="/UserinfoLogn"){
    next();
  }
  
  var token=sessionStorage.getItem("Token")
  if(!token){
    next("/UserinfoLogn")
  }  
  next()

})


